package ca.abubakrsagar.breadboardsim;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

/**
 * Creates a new MainSwitchController that will be used to control the state of
 * the main switch.
 * 
 * @author Sagar & Abubakr
 * @since June 14, 2012
 */
public class MainSwitchController implements MouseListener {

	private MainSwitch mainSwitch; // The mainSwitch object.

	/**
	 * Creates a new MainSwitchController while associating the local main
	 * switch with the specified
	 * 
	 * @param mainSwitch
	 *            The mainSwitch object.
	 */
	public MainSwitchController(MainSwitch mainSwitch) {
		this.mainSwitch = mainSwitch;
	}

	/**
	 * If the mouse was clicked on the main switch, switch its state.
	 */
	@Override
	public void mouseClicked(MouseEvent e) {
		// Only check if the mainSwitch was clicked and the event is not already
		// consumed.
		if (e.getSource() == mainSwitch && !e.isConsumed()) {
			if (mainSwitch.isOn()) {
				mainSwitch.setOn(false);
			} else {
				mainSwitch.setOn(true);
			}
		}
		e.consume(); // After the state has been changed, consume the mouse
						// event to prevent errors.

	}

	@Override
	public void mouseEntered(MouseEvent e) {
	}

	@Override
	public void mouseExited(MouseEvent e) {
	}

	@Override
	public void mousePressed(MouseEvent e) {
	}

	@Override
	public void mouseReleased(MouseEvent e) {
	}

}
